package com.share.web.action.template;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.share.bean.template.Template;
import com.share.service.template.TemplateService;
import com.share.web.action.base.BaseActionSupport;

@Controller
@Scope("prototype")
public class TemplateAction extends BaseActionSupport{

	private static final long serialVersionUID = 1L;

	private Template template ;
	
	private int tempItemId ;
	
	private Object[] ids ;

	public Object[] getIds() {
		return ids;
	}

	public void setIds(Object[] ids) {
		this.ids = ids;
	}

	@Resource
	private TemplateService ts ;

	public String addTemplate() {
		tempItemId = this.template.getTemplateItem().getTempItemId() ;
		this.ts.saveTemplate(template) ;
		
		return "reloadTemplate" ;
	}
	
	public String updateTemplate() {
		tempItemId = this.template.getTemplateItem().getTempItemId() ;
		this.ts.updateTemplate(template) ;
		return "reloadTemplate" ;
	}
	
	public String deleteTemplate() {
		this.ts.deleteTemplate(ids) ;
		
		return "reloadTemplate" ;
	}


	public int getTempItemId() {
		return tempItemId;
	}
	
	public Template getTemplate() {
		return template;
	}
	
	public TemplateService getTs() {
		return ts;
	}

	public String loadByIdTemplate() {
		
		this.getBaseform().getRequest().setAttribute("template",this.ts.loadByIdTemplate(template.getTemplateId())) ;
		
		return "updateTemplate" ;
	}
	
	public String queryAllTemplate() {
		this.getBaseform().getRequest().setAttribute("template",this.ts.findAllTemplate()) ;
		
		return "" ;
	}

	public void setTempItemId(int tempItemId) {
		this.tempItemId = tempItemId;
	}

	public void setTemplate(Template template) {
		this.template = template;
	}

	public void setTs(TemplateService ts) {
		this.ts = ts;
	}
	
}
